﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using BrokerBase.Lib.Person;
using BrokerBase.Lib.Policy;

namespace Broker.View.Converter
{
    public class PersonConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //IPerson p = value as IPerson;
            try
            {
                IScheme scheme = value as IScheme;

                string par = parameter.ToString();

                string info = null;

                if (scheme != null)
                {

                    if (par == "Holder" && scheme.Holder != null)
                    {
                        info = scheme.Holder.Name + "     " + (scheme.HolderSex == SexType.Male ? "男" : "女") + "     投保年龄:" + scheme.HolderAge +"岁";
                    }
                    else if (par == "Insurant" && scheme.Insurant != null)
                    {
                        info = scheme.Insurant.Name + "     " + (scheme.InsurantSex == SexType.Male ? "男" : "女") + "     投保年龄:" + scheme.InsurantAge+"岁";
                    }
                    else if (par == "Beneficiary" && scheme.Beneficiary != null)
                    {
                        info = scheme.Beneficiary.Name + "     " + (scheme.Beneficiary.Sex == SexType.Male ? "男" : "女");
                    }
                }

                return info;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
